import app
import requests


class EmployeeAPI:
    def __init__(self):
        self.url_add_employee = app.BASE_URL + "/api/sys/user"
        self.url_update_employee = app.BASE_URL + "/api/sys/user/{}"
        self.url_get_employee = app.BASE_URL + "/api/sys/user/{}"
        self.url_delete_employee = app.BASE_URL + "/api/sys/user/{}"

    # 员工添加
    def add_employee(self, add_employee_json):
        # 这里可以返回response对象方便后续测试类继续断言
        return requests.post(url=self.url_add_employee, json= add_employee_json, headers = app.headers_data)
    # 员工修改
    def update_employee(self,update_employee_json):
        employee_id = update_employee_json["employee_id"]
        url = self.url_update_employee.format(employee_id)
        return requests.put(url=url, json = update_employee_json, headers=app.headers_data)
    # 员工查询
    def get_employee(self, employee_json):
        employee_id = employee_json["employee_id"]
        url = self.url_get_employee.format(employee_id)
        return  requests.get(url = url, headers=app.headers_data)

    # 员工删除
    def delete_employee(self, employee_json):
        employee_id = employee_json["employee_id"]
        url = self.url_delete_employee.format(employee_id)
        return  requests.delete(url = url, headers=app.headers_data)
